<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="optparse-what-options-for.html" />
<link rel="prev" href="optparse-background.html" />
<link rel="parent" href="optparse-background.html" />
<link rel="next" href="optparse-what-options-for.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>14.3.1.1 Terminology</title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="14.3.1 Background"
  href="optparse-background.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="14.3.1 Background"
  href="optparse-background.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="14.3.1.2 what are options"
  href="optparse-what-options-for.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="optparse-background.html">14.3.1 Background</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="optparse-background.html">14.3.1 Background</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="optparse-what-options-for.html">14.3.1.2 What are options</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h3><a name="SECTION0016311000000000000000"></a><a name="optparse-terminology"></a>
<br>
14.3.1.1 Terminology
</h3>
<dl>
<dt><strong>argument</strong></dt>
<dd>a string entered on the command-line, and passed by the shell to
<code>execl()</code> or <code>execv()</code>.  In Python, arguments are elements of
<code>sys.argv[1:]</code> (<code>sys.argv[0]</code> is the name of the program being
executed).  <span class="Unix">Unix</span> shells also use the term ``word''.

<p>
It is occasionally desirable to substitute an argument list other
than <code>sys.argv[1:]</code>, so you should read ``argument'' as ``an element of
<code>sys.argv[1:]</code>, or of some other list provided as a substitute for
<code>sys.argv[1:]</code>''.
</dd>
<dt><strong>option   </strong></dt>
<dd>an argument used to supply extra information to guide or customize the
execution of a program.  There are many different syntaxes for
options; the traditional <span class="Unix">Unix</span> syntax is a hyphen (``-'') followed by a
single letter, e.g. <code>"-x"</code> or <code>"-F"</code>.  Also, traditional <span class="Unix">Unix</span>
syntax allows multiple options to be merged into a single argument,
e.g.  <code>"-x -F"</code> is equivalent to <code>"-xF"</code>.  The GNU project
introduced <code>"-"</code> followed by a series of hyphen-separated words,
e.g. <code>"-file"</code> or <code>"-dry-run"</code>.  These are the only two option
syntaxes provided by <tt class="module">optparse</tt>.

<p>
Some other option syntaxes that the world has seen include:

<ul>
<li> 
a hyphen followed by a few letters, e.g. <code>"-pf"</code> (this is
<em>not</em> the same as multiple options merged into a single argument)

<p>
</li>
<li> 
a hyphen followed by a whole word, e.g. <code>"-file"</code> (this is
technically equivalent to the previous syntax, but they aren't
usually seen in the same program)

<p>
</li>
<li> 
a plus sign followed by a single letter, or a few letters,
or a word, e.g. <code>"+f"</code>, <code>"+rgb"</code>

<p>
</li>
<li> 
a slash followed by a letter, or a few letters, or a word, e.g.
<code>"/f"</code>, <code>"/file"</code>

<p>
</li>
</ul>

<p>
These option syntaxes are not supported by <tt class="module">optparse</tt>, and they never will
be.  This is deliberate: the first three are non-standard on any
environment, and the last only makes sense if you're exclusively
targeting VMS, MS-DOS, and/or Windows.
</dd>
<dt><strong>option argument</strong></dt>
<dd>an argument that follows an option, is closely associated with that
option, and is consumed from the argument list when that option is.
With <tt class="module">optparse</tt>, option arguments may either be in a separate argument
from their option:
<div class="verbatim"><pre>
-f foo
--file foo
</pre></div>

<p>
or included in the same argument:
<div class="verbatim"><pre>
-ffoo
--file=foo
</pre></div>

<p>
Typically, a given option either takes an argument or it doesn't.
Lots of people want an ``optional option arguments'' feature, meaning
that some options will take an argument if they see it, and won't if
they don't.  This is somewhat controversial, because it makes parsing
ambiguous: if <code>"-a"</code> takes an optional argument and <code>"-b"</code> is
another option entirely, how do we interpret <code>"-ab"</code>?  Because of
this ambiguity, <tt class="module">optparse</tt> does not support this feature.
</dd>
<dt><strong>positional argument</strong></dt>
<dd>something leftover in the argument list after options have been
parsed, i.e. after options and their arguments have been parsed and
removed from the argument list.
</dd>
<dt><strong>required option</strong></dt>
<dd>an option that must be supplied on the command-line; note that the
phrase ``required option'' is self-contradictory in English.  <tt class="module">optparse</tt>
doesn't prevent you from implementing required options, but doesn't
give you much help at it either.  See <code>examples/required_1.py</code> and
<code>examples/required_2.py</code> in the <tt class="module">optparse</tt> source distribution for two
ways to implement required options with <tt class="module">optparse</tt>.
</dd>
</dl>

<p>
For example, consider this hypothetical command-line:
<div class="verbatim"><pre>
prog -v --report /tmp/report.txt foo bar
</pre></div>

<p>
<code>"-v"</code> and <code>"-report"</code> are both options.  Assuming that
<b class="programopt">--report</b> takes one argument, <code>"/tmp/report.txt"</code> is an option
argument.  <code>"foo"</code> and <code>"bar"</code> are positional arguments.

<p>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="14.3.1 Background"
  href="optparse-background.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="14.3.1 Background"
  href="optparse-background.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="14.3.1.2 what are options"
  href="optparse-what-options-for.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="optparse-background.html">14.3.1 Background</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="optparse-background.html">14.3.1 Background</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="optparse-what-options-for.html">14.3.1.2 What are options</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
